package sad;

import com.sun.javafx.css.StyleCacheEntry;
import java.security.Key;
import java.util.HashMap;
import java.util.Iterator;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 9:12
 * @description:
 */
public class SadDaoMap implements SadDao{
  private HashMap<String,Sad> map=new HashMap<String,Sad>();

  @Override
  public void save(Sad sad) {
    String key=sad.getEnglish();
    map.put(key,sad);
  }

  @Override
  public Sad query(String name) {
    if (map.containsKey(name)){
      return map.get(name);
    }
    return null;
  }

  @Override
  public void queryAll() {
    Iterator iterator=map.keySet().iterator();
    while (iterator.hasNext())
    {
      String Key= (String) iterator.next();
      Sad value = map.get(Key);
      System.out.println(value);
    }
  }

  @Override
  public void delete(String name) {
    if (map.containsKey(name)){
      map.remove(name);
      System.out.println("该单词已删除");
    }else {
      System.out.println("该单词不存在");
    }
  }
}
